home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / source.test < prev    next >
Text File  |  1993-02-17  |  3KB  |  96 lines

  1. # Commands covered:  source
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/source.test,v 1.8 93/02/17 13:22:56 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test source-1.1 {source command} {
  32.     set x "old x value"
  33.     set y "old y value"
  34.     set z "old z value"
  35.     exec cat << {
  36.     set x 22
  37.     set y 33
  38.     set z 44
  39.     } > source.file
  40.     source source.file
  41.     list $x $y $z
  42. } {22 33 44}
  43. test source-1.2 {source command} {
  44.     exec cat << {list result} > source.file
  45.     source source.file
  46. } result
  47.  
  48. test source-2.1 {source error conditions} {
  49.     list [catch {source} msg] $msg
  50. } {1 {wrong # args: should be "source fileName"}}
  51. test source-2.2 {source error conditions} {
  52.     list [catch {source a b} msg] $msg
  53. } {1 {wrong # args: should be "source fileName"}}
  54. test source-2.3 {source error conditions} {
  55.     exec cat << {
  56.     set x 146
  57.     error "error in sourced file"
  58.     set y $x
  59.     } > source.file
  60.     list [catch {source source.file} msg] $msg $errorInfo
  61. } {1 {error in sourced file} {error in sourced file
  62.     while executing
  63. "error "error in sourced file""
  64.     (file "source.file" line 3)
  65.     invoked from within
  66. "source source.file"}}
  67. test source-2.4 {source error conditions} {
  68.     exec cat << {break} > source.file
  69.     catch {source source.file}
  70. } 3
  71. test source-2.5 {source error conditions} {
  72.     exec cat << {continue} > source.file
  73.     catch {source source.file}
  74. } 4
  75. test source-2.6 {source error conditions} {
  76.     string tolower [list [catch {source _non_existent_} msg] $msg $errorCode]
  77. } {1 {couldn't read file "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
  78.  
  79. test source-3.1 {return in middle of source file} {
  80.     exec cat << {
  81.     set x new-x
  82.     return allDone
  83.     set y new-y
  84.     } > source.file
  85.     set x old-x
  86.     set y old-y
  87.     set z [source source.file]
  88.     list $x $y $z
  89. } {new-x old-y allDone}
  90.  
  91. catch {exec rm source.file}
  92.  
  93. # Generate null final value
  94.  
  95. concat {}
  96.